/** 
 * This library is free software; you can redistribute it and/or modify it under 
 * the terms of the GNU Lesser General Public License as published by the Free 
 * Software Foundation; either version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the Free Software Foundation, 
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */
package de.stoneageracer.core;

/**
 * This class acts as a container for global variables and constants
 * @author Philipp Jean-Jacques
 */
public abstract class SettingsManager {
    
    // general
    public static boolean showdebug = true;
    public static boolean console = false;
    public static final VersionNumber version = new VersionNumber(0.01f, "alpha");
    
    // graphics
    public static boolean gfx_lightscattering = true;
    public static boolean gfx_hdr = false;
    public static boolean gfx_motionblur = false;
    public static boolean gfx_bloom = true;
    public static boolean gfx_shadows = true;
    public static int     gfx_shadow_quality = 2;   // max 8 min 1 (affects FPS a LOT ... 1 looks ugly but 2 is fine
    
}

/**
 * This class is used to store nice version numbers and compares them
 * @author Philipp Jean-Jacques
 */
class VersionNumber implements Comparable<VersionNumber> {

    /**
     * Suffix for the version number
     */
    String suff;

    /**
     * Decimal version number
     */
    float number;

    /**
     * @param number primary version number
     * @param suff version number 
     */
    public VersionNumber(float number, String suff){
        this.number = number;
        this.suff = suff;
    }

    /**
     * This method is used to compare version numbers
     * @param t The version number that will be compared to
     * @return returns a value that is not 0 if the version number is not the same
     */
    public int compareTo(VersionNumber t) {
        if(t.number == number){
            return t.suff.compareTo(suff);
        }
        else{
            return (int) ((number - t.number)*100000);
        }
    }    
    /**
     * This method is used to parse Strings to VersionNumbers
     * @param str the String to parse
     * @return returns a VersionNumber object
     * @throws de.stoneageracer.core.VersionNumber.VersionNumberFormatException 
     */
    public static VersionNumber parseVersionNumber(String str) throws VersionNumberFormatException {
        return new VersionNumber(Float.parseFloat(str.replaceFirst("\\w+", "")), str.replaceAll("[0-9]+\\.?[0-9]*", ""));
    }

    /**
     * @return returns the version number as a String: primary version number + version suffix (e.g. 0.1a)
     */
    @Override
    public String toString(){
        return number + suff;
    }
    
    
    class VersionNumberFormatException extends Exception {
        
        /**
         * Sets the Exception message
         * @param msg the Exception message
         */
        public VersionNumberFormatException(String msg){
            super(msg);
        }
        
    }

}
